//
//  HBShakeResultHeaderCell.m
//  HuoBao
//
//  Created by chaiyanan on 15/12/10.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBShakeResultHeaderCell.h"

@interface HBShakeResultHeaderCell ()

@property (nonatomic, strong) UIImageView *headImageView;
@property (nonatomic, strong) UILabel *desLable;
@property (nonatomic, strong) UIButton *buyBtn;

@end

@implementation HBShakeResultHeaderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createCustomView];
    }
    return self;
}

- (void)createCustomView
{
    self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 10, SCREEN_WIDTH-30, (SCREEN_WIDTH-30)*ShareHeightPWidth)];
    self.headImageView.image = [UIImage imageNamed:@"Shake_Header"];
    [self.contentView addSubview:self.headImageView];
    
    self.msgLable = [self createLableWithTextColor:[LCCommon getColor:@"333333"] font:[UIFont boldSystemFontOfSize:18.0f] text:@"哇塞，人品大爆发！！！" textAlignment:NSTextAlignmentCenter frame:CGRectMake(15, self.headImageView.y+56*(self.headImageView.height/235), SCREEN_WIDTH-30, 18) superView:self.contentView];
    self.rateLable = [self createLableWithTextColor:[LCCommon getColor:@"fc353b"] font:[UIFont boldSystemFontOfSize:41.0f] text:@"+0.4%" textAlignment:NSTextAlignmentCenter frame:CGRectMake(15, self.headImageView.y+74*(self.headImageView.height/235)+18, SCREEN_WIDTH-30, 41) superView:self.contentView];
    if (isIphone4or5)
    {
        self.rateLable.y = self.rateLable.y - 10;
    }
    
    self.desLable = [self createLableWithTextColor:[LCCommon getColor:@"b1b1b1"] font:[UIFont systemFontOfSize:11.0f] text:@"小桔掐指一算，贵人今日财运很旺" textAlignment:NSTextAlignmentLeft frame:CGRectMake(15, self.headImageView.y+self.headImageView.height+25, SCREEN_WIDTH-30, 11) superView:self.contentView];
    
    self.buyBtn = [self createButtonWithFrame:CGRectMake(15, self.desLable.y+self.desLable.height+10, SCREEN_WIDTH-30, 44) normalBackgroundColor:[LCCommon getColor:@"fa9838"] disabledBackgroundColor:[LCCommon getColor:@"fa9838"]  higlightedBackgroundColor:[LCCommon getColor:@"e47910"] normalFontColor:[LCCommon getColor:@"ffffff"] higlightedFontColor:[LCCommon getColor:@"ffffff"] disabledFontColor:[LCCommon getColor:@"fd7a7a"] title:@"抓住机会，立即投资" textAlignment:NSTextAlignmentCenter font:[UIFont systemFontOfSize:16] superView:self.contentView];
    self.buyBtn.enabled = YES;
    
    [self createSepratorLineWithFrame:CGRectMake(15, Height_HBShakeResultHeaderCell-1-1/([UIScreen mainScreen].scale), SCREEN_WIDTH-30, 1/([UIScreen mainScreen].scale)) backgroundColor:[LCCommon getColor:@"585858"] superView:self.contentView];
}

- (UILabel *)createLableWithTextColor:(UIColor *)color font:(UIFont *)font text:(NSString *)text textAlignment:(NSTextAlignment)textAlignment frame:(CGRect)frame superView:(UIView *)superView
{
    UILabel *lable = [[UILabel alloc]initWithFrame:frame];
    lable.textColor = color;
    lable.font = font;
    lable.text = text;
    lable.textAlignment = textAlignment;
    [superView addSubview:lable];
    return lable;
}

- (UIView *)createSepratorLineWithFrame:(CGRect)frame backgroundColor:(UIColor *)bgColor superView:(UIView *)superView
{
    UIView *sepratorLine = [[UIView alloc]initWithFrame:frame];
    sepratorLine.backgroundColor = bgColor;
    [superView addSubview:sepratorLine];
    return sepratorLine;
}

- (UIButton *)createButtonWithFrame:(CGRect)frame normalBackgroundColor:(UIColor *)normalBGColor disabledBackgroundColor:(UIColor *)disabledBGColor higlightedBackgroundColor:(UIColor *)higlightedBGColor  normalFontColor:(UIColor *)normalFontColor higlightedFontColor:(UIColor *)higlightedFontColor disabledFontColor:(UIColor *)disabledFontColor title:(NSString *)title textAlignment:(NSTextAlignment)textAlignment font:(UIFont *)font superView:(UIView *)superView
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = frame;
    [button setBackgroundColor:normalBGColor];
    [button setBackgroundColor:normalBGColor forState:UIControlStateNormal];
    [button setBackgroundColor:disabledBGColor forState:UIControlStateDisabled];
    [button setBackgroundColor:higlightedBGColor forState:UIControlStateHighlighted];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:normalFontColor forState:UIControlStateNormal];
    [button setTitleColor:disabledFontColor forState:UIControlStateDisabled];
    [button setTitleColor:higlightedFontColor forState:UIControlStateHighlighted];
    button.titleLabel.font = font;
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    [superView addSubview:button];
    button.enabled = NO;
    [button.layer setCornerRadius:4.0f];
    button.layer.masksToBounds = YES;
    return button;
}

- (void)clickButton:(UIButton *)sender
{
    if (self.ActionClickToBuy)
    {
        self.ActionClickToBuy();
    }
}

@end
